package tw.com.hitevision.whiteboard.android;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;

public class AppFinder {
    public static boolean isAnnotationInstalled(Context context){
        return isAppInstalled(context,context.getString(R.string.package_annotation));
    }

    public static boolean isWebImageInstalled(Context context){
        return isAppInstalled(context,context.getString(R.string.package_web_image));
    }

    public static boolean isVisualizerInstalled(Context context){
        return isAppInstalled(context,context.getString(R.string.package_visualizer));
    }

    public static boolean isSplitMenuInstalled(Context context){
        return isAppInstalled(context,context.getString(R.string.package_split_mode));
    }

    public static boolean isShareAppInstalled(Context context){
        return isAppInstalled(context,context.getString(R.string.package_sharer));
    }


    private static boolean isAppInstalled(Context context, String packagename) {
        PackageInfo packageInfo;
        try {
            packageInfo = context.getPackageManager().getPackageInfo(packagename, 0);
        } catch (PackageManager.NameNotFoundException e) {
            packageInfo = null;
            e.printStackTrace();
        }
        if (packageInfo == null) {
            return false;
        } else {
            return true;
        }
    }
}
